﻿namespace DesktopRibbon.Launcher
{
    using System.Windows.Media;
    using System.Collections;
    using System.ComponentModel;

    /// <summary>
    ///  The ILauncherItem is the base interface for any item that can be put in the DesktopRibbonControl.
    /// </summary>
    abstract class LauncherItem : INotifyPropertyChanged
    {
        #region Properties

        /// <summary>
        /// The label will be shown near the icon
        /// </summary>
        public abstract string Label
        {
            get;
        }

        /// <summary>
        /// The small image source will be used to display the launcher's icon when there is not enough
        /// space for the large image source.
        /// </summary>
        public abstract ImageSource SmallImageSource
        {
            get;
        }

        /// <summary>
        /// The large image source will be used to display the launcher's icon whenever there is enough space.
        /// </summary>
        public abstract ImageSource LargeImageSource
        {
            get;
        }

        /// <summary>
        /// IsLaunchable specifies whether this ILauncherItem itself can actually be launched. When IsLaunchable is false,
        /// Launch () is usually implemented with an emtpy function body.
        /// Non-launchable should have children, because this is the only purpose they can serve.
        /// When a launchable item has children, it is displayed in a SplitButton.
        /// </summary>
        public abstract bool IsLaunchable
        {
            get;
        }

        /// <summary>
        /// Launcher Items can have children. The children are commonly displayed as menu items or gallery items.
        /// Children have to implement the ILauncherItem.
        /// <seealso cref="IsLaunchable"/>
        /// </summary>
        public abstract IList Children
        {
            get;
        }

        #endregion

        #region Events

        /// <summary>
        /// Implements INotifyPropertyChanged.
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        #region Methods

        /// <summary>
        /// Launch will execute any action that is associated to the Launcher item.
        /// When IsLaunchable is false, Launch() should do nothing.
        /// </summary>
        /// <returns>True when the item has been successfully launched, false otherwise.</returns>
        public abstract bool Launch();

        protected void OnPropertyChanged(string property)
        {
            System.Diagnostics.Trace.Write(string.Format("ShellLaucnherItem.OnPropertyChanged id: {0}\n", System.Threading.Thread.CurrentThread.ManagedThreadId));
            var handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(property));
            }
        }

        #endregion

    }
}
